package com.pp.ent.util;

/**
 * Created by dengqu on 2017/2/24.
 */

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

public class GenericsType
{
    private Type[] argTypes;

    public GenericsType(Type genericFieldType)
    {
        if ((genericFieldType instanceof ParameterizedType))
        {
            ParameterizedType aType = (ParameterizedType)genericFieldType;
            this.argTypes = aType.getActualTypeArguments();
        }
    }

    public TypeVo getType(int index)
            throws Exception
    {
        TypeVo vo = new TypeVo();
        if (this.argTypes.length > 0)
        {
            if ((index >= this.argTypes.length) || (index < 0)) {
                throw new RuntimeException("������������" + (index < 0 ? "��������0" : "����������������"));
            }
            if ((this.argTypes[index] instanceof ParameterizedType))
            {
                vo.setNextType(this.argTypes[index]);
                vo.setCls((Class)((ParameterizedType)this.argTypes[index]).getRawType());
            }
            else
            {
                vo.setCls((Class)this.argTypes[index]);
            }
        }
        else
        {
            vo.setCls(Object.class);
        }
        return vo;
    }
}

